#include <WiFi.h>
#include <WiFiUdp.h>

WiFiUDP udp;
// IPAddress targetIP(192, 168, 57, 249); // 目标IP地址
 IPAddress targetIP(172, 31, 18, 25); // 目标IP地址
const int targetPort = 9;            // 目标端口

int sendUDPPacket() {
  // 开始UDP包
  if(udp.beginPacket(targetIP, targetPort) == 1) {
    // 写入数据
    udp.print("Hello UDP");
    
    // 发送包
    if(udp.endPacket() == 1) {
      Serial.println("UDP packet sent successfully");
      return 0;
    } else {
      Serial.println("Failed to send UDP packet");
      return -1;
    }
  } else {
    Serial.println("Failed to begin UDP packet");
    return -1;
  }
}




